package com.dailyblue.javaee.controller;


import com.alibaba.fastjson2.JSONArray;
import com.dailyblue.javaee.bean.Emp;
import com.dailyblue.javaee.service.EmpService;
import com.dailyblue.javaee.service.impl.EmpServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/emp_find_page_ajax")
public class EmpFindPageAjaxController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int page = 1;
        String p = request.getParameter("page");
        if (p != null) {
        page=Integer.parseInt(p);
        }
        EmpService service =new EmpServiceImpl();
        List<Emp> list=service.find(page);
        response.setContentType("application/json;charset=utf-8");
        String json = JSONArray.toJSONString(list);
        PrintWriter out =response.getWriter();
        out.println(json);
    }
}
